package com.socialuni.center.web.factory;

import com.socialuni.sdk.api.model.RO.comment.ReplyCommentRO;
import com.socialuni.sdk.api.model.RO.comment.TalkCommentRO;
import com.socialuni.sdk.api.model.RO.user.SocialCommentUserRO;
import com.socialuni.center.web.utils.UnionIdDbUtil;
import com.socialuni.sdk.factory.ListConvertUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 不需要像帖子一样，每次有回复都刷新，因为不愁看，且你评论后的，有动静你会有通知
 */
@Data
@Component
@Slf4j
public class CenterCommentROFactory {
    //需要user因为，user需要外部传入，区分center和social
    //用户详情
    public static TalkCommentRO newHomeCommentRO(TalkCommentRO commentRO) {
        String id = UnionIdDbUtil.createCommentUid(commentRO.getId());

        SocialCommentUserRO userRO = CenterCommentUserROFactory.newCommentUserRO(commentRO.getUser());

        List<TalkCommentRO> childComments = CenterCommentROFactory.newHomeCommentROS(commentRO.getChildComments());

        commentRO.setId(id);
        commentRO.setUser(userRO);
        commentRO.setChildComments(childComments);

        if (commentRO.getReplyComment() != null) {
            ReplyCommentRO replyComment = CenterReplyCommentROFactory.newHomeReplyCommentRO(commentRO.getReplyComment());
            commentRO.setReplyComment(replyComment);
        }

        return commentRO;
    }

    public static List<TalkCommentRO> newHomeCommentROS(List<TalkCommentRO> ROS) {
        return ListConvertUtil.toList(ROS, CenterCommentROFactory::newHomeCommentRO);
    }
}